package com.lh;


import org.kie.api.runtime.KieSession;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: linghao
 * @since: 2022/12/3
 */
public class ExcuteRule {

    public static void main(String[] args) throws Exception {
//        testdrl();
//        testdrl2();
//        testdrl3();
        testdrl4();
    }

    private static void testdrl4() throws Exception{
        KieSession kieSession = KieSessionFactory.newKieSession("test4.drl");

        RuleFact ruleFact = new RuleFact();
        Map<String,Object> map = new HashMap<>();
        map.put("val1","D");
        map.put("val2","a");
        map.put("in2_val4","游戏2");
        map.put("in_val21","1234");
        ruleFact.setFieldToValue(map);
        kieSession.insert(ruleFact);

        kieSession.fireAllRules();
        KieSessionFactory.disposeKieSession();
    }


    private static void testdrl3() throws Exception {
        KieSession kieSession = KieSessionFactory.newKieSession("test3.drl");

        RuleFact ruleFact = new RuleFact();
        Map<String,Object> map = new HashMap<>();
        map.put("val1","D");
        map.put("val2","a");
        map.put("in2_val4","游戏2");
        map.put("in_val21","1234");
        ruleFact.setFieldToValue(map);

        List<String> blackList = new ArrayList<>();
//        blackList.add("房地产");
//        blackList.add("游戏");
//        blackList.add("游戏2");
//        blackList.add("游戏3");
//        blackList.add("P2P");
//        blackList.add("123");
//        blackList.add("1234");

        kieSession.insert(ruleFact);
        kieSession.insert(blackList); //黑名单为空时传入空list

        kieSession.fireAllRules();

        KieSessionFactory.disposeKieSession();
    }

    private static void testdrl2() throws Exception {
        KieSession kieSession = KieSessionFactory.newKieSession("test2.drl");

        RuleFact ruleFact = new RuleFact();
        Map<String,Object> map = new HashMap<>();
        map.put("val1","DD");
        ruleFact.setFieldToValue(map);

        List<String> blackList = new ArrayList<>();
        blackList.add("房地产");
        blackList.add("游戏");
        blackList.add("游戏2");
        blackList.add("游戏3");
        blackList.add("P2P");

        kieSession.insert(ruleFact);
        kieSession.insert(blackList);

        kieSession.fireAllRules();

        KieSessionFactory.disposeKieSession();
    }

    private static void testdrl() throws Exception {
        KieSession kieSession = KieSessionFactory.newKieSession("test.drl");

//        Company company = new Company();
//        List<String> targetList = new ArrayList<>();
//        targetList.add("教育");
//        targetList.add("P2P2");
//        company.setScopes(targetList);

        List<String> blackList = new ArrayList<>();
        blackList.add("房地产");
        blackList.add("游戏");
        blackList.add("游戏2");
        blackList.add("游戏3");
        blackList.add("P2P");

//        kieSession.insert(company);
        kieSession.insert(blackList);

        kieSession.fireAllRules();

        KieSessionFactory.disposeKieSession();
    }
}
